Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify Python binding of StorageConfig #371

Merged

Conversation

kylebarron
Copy link
Contributor

I'm starting to read through the storage binding for #266.

As it stands, you recreate the content of the struct in the Python binding as well, and then you convert the content of the struct in the Python bindings to the content of the struct in the Rust code.

In my opinion it's best to have as little logic as possible in the binding code and make it a slim wrapper around the underlying core Rust code. Minimizing the logic in the bindings also makes it simpler to make bindings to other languages in the future (#356)

Comment on lines +33 to +41
impl From<PyS3Credentials> for StaticS3Credentials {
fn from(credentials: PyS3Credentials) -> Self {
StaticS3Credentials {
access_key_id: credentials.access_key_id,
secret_access_key: credentials.secret_access_key,
session_token: credentials.session_token,
}
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's useful to have a value-to-value From impl instead of just an impl on &PyS3Credentials so that you can avoid the clones when not needed.

}

#[classmethod]
#[pyo3(signature = (
bucket,
prefix,
endpoint_url = None,
allow_http = None,
allow_http = false,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

allow_http can only be a bool, so why not default to false instead of defaulting to None and then unwrapping?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no reason, just moving fast

allow_http: bool | None
region: str | None

def __init__(self, storage: Memory | Filesystem | S3): ...
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no #[new] method defined on StorageConfig, so it wasn't possible to directly construct this anyways.

Comment on lines +183 to +185
impl AsRef<StorageConfig> for PyStorageConfig {
fn as_ref(&self) -> &StorageConfig {
&self.0
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This AsRef impl means that if you have a PyStorageConfig and you want to access an &StorageConfig, you can just call .as_ref().

Copy link
Contributor

@mpiannucci mpiannucci left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Thanks for cleaning this up

@mpiannucci mpiannucci merged commit 587090e into earth-mover:main Nov 4, 2024
2 checks passed
@kylebarron kylebarron deleted the kyle/simplify-storage-binding branch November 4, 2024 22:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants